package cn.iocoder.yudao.boot.common.exception;

import cn.iocoder.yudao.boot.common.constant.GlobalResultCodeConstants;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.springframework.http.HttpStatus;

/**
 * 业务逻辑异常 Exception
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class ServiceException extends RuntimeException {
    private HttpStatus httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    private String code;
    private String message;

    public ServiceException(ResultCode errorCode) {
        this.code = errorCode.getCode();
        this.message = errorCode.getMsg();
    }

    public ServiceException(String message) {
        this.code = GlobalResultCodeConstants.INTERNAL_SERVER_ERROR.getCode();
        this.message = GlobalResultCodeConstants.INTERNAL_SERVER_ERROR.getMsg();
    }

    public ServiceException(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ServiceException(HttpStatus httpStatus, String message) {
        this.httpStatus = httpStatus;
        this.code = GlobalResultCodeConstants.INTERNAL_SERVER_ERROR.getCode();
        this.message = message;
    }

    public ServiceException(HttpStatus httpStatus, String code, String message) {
        this.httpStatus = httpStatus;
        this.code = code;
        this.message = message;
    }
}
